package com.czm.cardgllery;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * 控制fling抛掷速度的RecyclerView
 * Created by czm on 6/26/17.
 */
public class SpeedRecyclerView extends RecyclerView {
    private float scale = 0.1f; // 减速因子

    public SpeedRecyclerView(Context context) {
        super(context);
    }

    public SpeedRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public SpeedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    /**
     * 在RecyclerView中设置其减速因子 默认0.5
     * @param scale
     */
    public void setflingScale(float scale){
        this.scale = scale;
    }
    @Override
    public boolean fling(int velocityX, int velocityY) {
        velocityX *= scale;
        velocityY *= scale;
        return super.fling(velocityX, velocityY);
    }
}
